unit uInterfaces;

{$mode objfpc}{$H+}
{$i orcis.inc}

interface

uses
    Controls, sqldb,
    uTypes;

type

    { TISInterfacedObject }

    // Simple interfaced object without references counting
    TISInterfacedObject = class(IUnknown)
        function QueryInterface({$IFDEF FPC_HAS_CONSTREF}constref{$ELSE}const{$ENDIF} iid: tguid; out obj): longint; callconv;
        function _AddRef: longint; callconv;
        function _Release: longint; callconv;
    protected
        procedure Init; virtual;
        procedure Done; virtual;
    public
        constructor Create; virtual;
        destructor Destroy; override;
    end;

    // Structures
    // =================================================================================================================

    IISDataList = interface;
    IISDataTree = interface;

    // Data item for lists and trees
    IISDataItem = interface
    ['{9F34A507-E04C-42A5-8D63-EDA70A31258C}']
        function GetCaption: string;
        procedure SetCaption(const ACaption: string);
        function GetVisible: Boolean;
        procedure SetVisible(const AVisible: Boolean);

        property Caption: string;
        property Visible: Boolean;
    end;

    IISDataListItem = interface (IISDataItem)
    ['{F2DAA694-6ED3-4D1F-A7D7-924D5C04DA73}']
        function GetOwnerList: IISDataList;
        procedure SetOwnerList(const AList: IISDataList);
    end;

    IISDataTreeItem = interface (IISDataListItem)
    ['{F2DAA694-6ED3-4D1F-A7D7-924D5C04DA73}']
        function GetOwnerTree: IISDataTree;
        procedure SetOwnerTree(const AList: IISDataTree);

        function GetChildList: IISDataList;
    end;

    // List of data items
    IISDataList = interface
    ['{95035882-F67F-4EBC-9A0D-D96F2D5EF987}']
        procedure AddItem(const AItem: IISDataListItem);
        procedure DeleteItem(const AIndex: Integer);
        function GetItemIndex(const AItem: IISDataListItem): Integer;
        function GetItem(const AIndex: Integer): IISDataListItem;

        function GetCount: Integer;
    end;

    IISDataTreeList = interface (IISDataList)
    ['{36589485-1E2A-4149-8D49-23CED7688B4F}']
        function GetOwnerItem: IISDataTreeItem;
        function GetOwnerTree: IISDataTree;
    end;

    // Tree of data items
    IISDataTree = interface
    ['{1DA1DFF3-678B-48EB-9DB7-943031AC7C3A}']
        function GetRoot: IISDataList;
        function GetCount: Integer;
        function GetItem(const AIndex: Integer): IISDataTreeItem;
        function GetItemIndex(const AItem: IISDataTreeItem): Integer;
    end;

    // Interfaces for interaction between units, modules
    // and core
    // =================================================================================================================

    IISFrameContainer = interface;

    { IISFrame }

    IISFrame = interface
    ['{12D667B5-56FB-4988-8423-51501E3EC457}']
        function GetContainer: IISFrameContainer;
        procedure SetContainer(AValue: IISFrameContainer);
        function GetTitle: string;
        procedure SetTitle(const AValue: string);

        property Title: string read GetTitle write SetTitle;
        property Container: IISFrameContainer read GetContainer write SetContainer;
    end;

    // Frame container
    // -----------------------------------------------------
    IISFrameContainer = interface
    ['{0C98016A-9C9E-46A0-A6C4-3940C42B80F9}']
        property Frame: IISFrame;
    end;

    IISFrameManager = interface
    ['{F5A4BD9A-B2B3-4DE6-B4D6-17746961D75B}']
        property Count: Integer;
        function GetByIndex(const AIndex): IISFrameContainer;
        function GetByTag(const ATag: string): IISFrameContainer;
    end;

    // Messaging
    // =================================================================================================================

    IISMessageTarget = interface;

    IISMessage = interface
    ['{C8B0ED0E-40EB-4B21-9CF8-D35692F0DA07}']
        function GetMsg: cardinal;
        function GetMsgType: TISMessageType;
        function GetResult: TISMessageResult;
        function GetTarget: IISMessageTarget;
        procedure SetMsg(AValue: cardinal);
        procedure SetMsgType(AValue: TISMessageType);
        procedure SetResult(AValue: TISMessageResult);
        procedure SetTarget(AValue: IISMessageTarget);
        procedure Free;
        property Target: IISMessageTarget read GetTarget write SetTarget;
        property MsgType: TISMessageType read GetMsgType write SetMsgType;
        property Msg: cardinal read GetMsg write SetMsg;
        property Result: TISMessageResult read GetResult write SetResult;
    end;

    IISMessageTarget = interface
    ['{ECBE84A2-A7A6-4B2A-8CB2-12005BBDF7DB}']
        function GetMTID: string;
        procedure SetMTID(AValue: string);
        function ProcessMessage(AMsg: IISMessage): Boolean;
        property MTID: string read GetMTID write SetMTID;
    end;

    IISModule = interface;

    // Main application and form
    // -----------------------------------------------------
    IISCore = interface
    ['{95D36432-9F11-49FF-8BE9-2BAB692A2CD7}']
        // Modules
        // -------------------------------------------------
        procedure RegisterModule(AModule: IISModule);
        function ModuleByCode(const ACode: string): IISModule;

        // Database
        // -------------------------------------------------
        function GetDBConnection: TSQLConnection;

        // Messaging
        // -------------------------------------------------
        //function PostMessage(AMsg: TISMessage): TISMessage;
        //procedure RegMessageTarget(AMsgTarget: IISMessageTarget);
        //procedure UnregMessageTarget(AMsgTarget: IISMessageTarget);

        // Open new web page
        procedure NewWebPage(
            const AURL: string;             // URL address
            const AEngine: TRenderEngine;   // Rendering engine
            const AActivate: Boolean);      // Activate page after open
    end;

    IISPanel = interface
    ['{3965045A-EDE2-4B95-892E-67B47DDFC56D}']
        function GetCode: string;
        function GetCaption: string;
        function GetPanel: TWinControl;
        function GetFrame: TWinControl;

        procedure EmbedInto(aSurface: TWinControl);
    end;

    IISPanelFabric = interface
        function GetPanel(const aCode: string): IISPanel;
    end;

    IISModule = interface
    ['{632E2A38-08FF-4467-A2DB-39F05985CD21}']
        function GetCode: string;

        procedure Init(ACore: IISCore);
        procedure Done;

        function GetPanel: IISPanel;
        function GetFrame: IISFrameContainer;

        function ExecuteCommand(const ACmd: string; AParams: array of Pointer): string;
    end;

implementation

{ TISInterfacedObject }

function TISInterfacedObject.QueryInterface({$IFDEF FPC_HAS_CONSTREF}constref{$ELSE}const{$ENDIF} iid: tguid; out obj): longint; stdcall;
begin
    if GetInterface(IID, Obj) then
        Result := S_OK
    else
        Result := E_NOINTERFACE;
end;

function TISInterfacedObject._AddRef: longint; stdcall;
begin
    Result := -1;
end;

function TISInterfacedObject._Release: longint; stdcall;
begin
    Result := -1;
end;

procedure TISInterfacedObject.Init;
begin

end;

procedure TISInterfacedObject.Done;
begin

end;

constructor TISInterfacedObject.Create;
begin
    Init;
end;

destructor TISInterfacedObject.Destroy;
begin
    Done;
    inherited;
end;

end.

